
import {createStore} from 'vuex'

export default createStore({
  state: {
    loginInfo: null,
    token: '',
    scrollFlag: false,
  },
  mutations: {
    setloginInfo(state, loginInfo) {
      state.loginInfo = loginInfo
      sessionStorage.setItem('loginInfo', JSON.stringify(loginInfo))
    },
    setToken(state, token) {
      state.token = token
      sessionStorage.setItem('token', token)
    },
    setScrollFlag(state, scrollFlag) {
      state.scrollFlag = scrollFlag
    },
    clearLoginInfo(state) {
      state.loginInfo = null
      state.token = ''
      sessionStorage.removeItem('token')
      sessionStorage.removeItem('loginInfo')
    },
  },
  getters: {
    getloginInfo(state) {
      return state.loginInfo || JSON.parse(sessionStorage.getItem('loginInfo') as string)
    },

    getToken(state) {
      return state.token || sessionStorage.getItem('token')
    },

    getScrollFlag(state) {
      return state.scrollFlag
    },
  },
})